<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class MemberAction extends CommonAction {

    public function index(){

        
        $db_members = M("Members"); 
        $db_members_status = M("MembersStatus");
        
        //$map['is_del'] = 0;
        $map['status'] = array('neq','0');
        $members = $db_members->where($map)->order('is_del')->select();
        //dump($members);
        
        for($i=0; $i<count($members); $i++){
            $members[$i]['status'] = $db_members_status->where(array('status_id'=>$members[$i]['status']))->getField('status_describe');
        }
        
        $this->assign('members', $members);
        
    	$this->display();

    }
    
    public function applicationPage(){
        
        $db_members = M('Members');
        
        $aplLearners = $db_members->where(array("is_del"=>0, "status"=>0))->select();
        $fpwdLearners = $db_members->where(array("is_del"=>0, "status"=>2))->select();
        
        $this->assign("aplLearners", $aplLearners);
        $this->assign("fpwdLearners", $fpwdLearners);
        
        $this->display();
        
    }
    
    public function runApprove(){
        
        $id = I('id', -1);
        
        $db_members = M('Members');
        
        if( $db_members->where(array("id"=>$id))->setField('status',1) ){
            $db_members->where(array("id"=>$id))->setField('approve_time', date( "y-m-d H:i:s", time()));
            $this->ajaxReturn(array('status' =>  1, 'info' => '成功！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
        }else{
            $this->ajaxReturn(array('status' =>  0, 'info' => '失败！', 'data' => null, 'jumpUrl' => null ));
        }
    }
    
    public function runLearnerDel(){
        $id = I('id', -1);
        
        if( M('Members')->where(array("id"=>$id))->delete() ){
            $this->ajaxReturn(array('status' =>  1, 'info' => '成功！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
        }else{
            $this->ajaxReturn(array('status' =>  0, 'info' => '失败！', 'data' => null, 'jumpUrl' => null ));
        }
    }
    
    public function runResetPwd(){
        $id = I('id', -1);
        
        $db_members = M('Members');
        
        if( $db_members->where(array("id"=>$id))->setField("password", md5("111111")) ){
            $db_members->where(array("id"=>$id))->setField("status", 1 );
            $this->ajaxReturn(array('status' =>  1, 'info' => '密码重置成功！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
        }else{
            if( $db_members->where(array("id"=>$id))->getField("password") == md5("111111") ){
                $db_members->where(array("id"=>$id))->setField("status", 1 );
                $this->ajaxReturn(array('status' =>  2, 'info' => '密码重置成功！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
            }else{
                $this->ajaxReturn(array('status' =>  0, 'info' => '密码重置失败！', 'data' => null, 'jumpUrl' => null ));
            }
            
        }
    }
    
    public function runCancelPwd(){
        $id = I('id', -1);
        $db_members = M('Members');
        if( $db_members->where(array("id"=>$id))->setField("status", 1) ){
            $this->ajaxReturn(array('status' =>  1, 'info' => '操作成功！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
        }else{
            $this->ajaxReturn(array('status' =>  0, 'info' => '操作失败！', 'data' => null, 'jumpUrl' => U('applicationPage') ));
        }
    }
    
    
    
    
    
    public function delMemberInfo(){
        $db_members = M('Members');
        $db_m_members_pdoc = M('MMembersPdoc');
        
        $id = I('id', -1);
        
        if($db_members->where(array('id'=>$id))->delete()){
            $db_m_members_pdoc->where(array('uid'=>$id))->delete();
            $this->ajaxReturn(array('status' =>  1, 'info' => '操作成功！', 'data' => null, 'jumpUrl' => U('index') ));
        }else{
             $this->ajaxReturn(array('status' =>  0, 'info' => '操作失败！', 'data' => null, 'jumpUrl' => U('index') ));
        }
        
        
    }
    
    public function cancelMemberInfo(){
        $db_members = M('Members');
        $id = I('id', -1);
        if($db_members->where(array('id'=>$id))->setField('is_del', 1)){
            $this->ajaxReturn(array('status' =>  1, 'info' => '操作成功！', 'data' => null, 'jumpUrl' => U('index') ));
        }else{
            $this->ajaxReturn(array('status' =>  0, 'info' => '操作失败！', 'data' => null, 'jumpUrl' => U('index') ));
        }
    }
    
    public function resetMemberInfo(){
        $db_members = M('Members');
        $id = I('id', -1);
        if($db_members->where(array('id'=>$id))->setField('is_del', 0)){
            $this->ajaxReturn(array('status' =>  1, 'info' => '操作成功！', 'data' => null, 'jumpUrl' => U('index') ));
        }else{
            $this->ajaxReturn(array('status' =>  0, 'info' => '操作失败！', 'data' => null, 'jumpUrl' => U('index') ));
        }
    }
    
    
}
